<template>
	<view class="">
		<scroll-view scroll-y="true" :style="{height: scrollHeight}">
			<view class="mt-5" v-if="u_loadmore">
				<u-loadmore status="loading" icon-type="circle" />
			</view>
		<!-- 商品分类 -->
			<view class="" v-else></view>
		</scroll-view>
		
		<view class="seach">
			<u-navbar :is-back="false" :border-bottom="false" :background="background">
				<view class="d-flex a-center j-sb w-100">
					<view class="span-5 pl-2 py-2"  @click="backtrack_img">
						<u-icon name="arrow-left" color="#ffffff" size="40"></u-icon>
					</view>
					<view class="font-lg font-weight text-white">业务员</view>
					<view class="span-5"></view>
				</view>
			</u-navbar>
		</view>
		<view class="">
			<view class="m-2 px-3 bg-white rounded-10">
				<view class="py-3 d-flex j-sb border-bottom">
					<view class="font-weight font-35">姓名<text class="text-red">*</text></view>
					<view class="">
						<input type="text" v-model="user_name" @input="name_input" value="" class="text-right" placeholder="请输入姓名" />
					</view>
				</view>
				<view class="py-3 d-flex j-sb border-bottom">
					<view class="font-weight font-35">手机</view>
					<view class="">
						<input type="text" v-model="user_mobile" @input="mobile_input" value="" class="text-right" placeholder="请输入手机号" />
					</view>
				</view>
				<view class="py-3 d-flex j-sb">
					<view class="font-weight font-35">停用帐号</view>
					<view class="">
						<u-switch v-model="is_show" size="43" @change="toggle"></u-switch>
					</view>
				</view>
			</view>
		</view>	
			
		<view class="footer"></view>
		<view class="position-fixed bottom-0 w-100 bg-white py">
			<view class="d-flex sub j-sb p-2">
				<button type="warn" class="dele" @click="save">保存</button>
				<button type="warn" class="rele" @click="sub_next">取消</button>
			</view>	
		</view>
		
	</view>
</template>

<script>
	export default{
		data(){
			return {
				background: '#fa7226',
				backgroundSize: 'cover',
				items:JSON.parse(uni.getStorageSync("terrace_item")),
				user_name:"", // 姓名
				user_id:"", // 会员id
				mobile:"", // 手机号
				company:"", // 公司名称
				their:"", // 所属地区
				minute:"", // 详细地址
				remarks:"", // 备注
				
				
				tally:"", // 客户标签
				
				user_show:false, // 开关
				user_rank:"", // 默认报价
				user_item:"", // 会员id
				
				
				bottomShow:false,
				addressTab:"", // 地址tabbar
				addressList:"", // 地址列表
				address_show:false,
				
				province_show:false,
				city_show:false,
				county_show:false,
				
				provinceList:"", // 省的列表
				province_name:"", // 省 的名字
				cityList:"", // 市的列表
				city_name:"" ,// 市的名字
				countyList:"", // 县区的列表
				county_name:"" ,// 县区的名字
				street_name:"", // 街道名字
				street_id:"", // 街道id
				address_name:"", // 地址
				address_default:"", // 默认地址
				
				please:false,
				street_show:false,
				
				items_province:"",
				items_city:"",
				items_county:"",
				items_street:"",
			}
		},
		onReady() {
			let _this=this
			uni.getSystemInfo({
				success(resu) {
					const query = uni.createSelectorQuery()
					query.select('.footer').boundingClientRect()
					query.exec(function(res) {
						_this.scrollHeight = resu.windowHeight - res[0].top + 'px';
					})
				}
			})
		},
		methods:{
			// 返回
			backtrack_img(){
				uni.navigateBack({
					delta:1
				})
			},
			name_input(e){
				this.user_name=e.detail.value
			},
			// 显示切换
			toggle(e){
				if(e){
					this.is_show=1
				}else{
					this.is_show=0
				}
				
			},
			// 保存
			sub_next(){
				let tag_id=[]
				if(this.tally){
					tag_id=this.tally.map(v=>{
						return v.checked?v.tag_id:""
					})
				}
				
				this.$H.post("v2/store/user/review",{
					user_id:this.user_id,
					user_name:this.user_name,
					mobile_phone:this.mobile,
					company_name:this.company,
					rank_id:this.user_item.rank_id,
					tag_id:this.tally?tag_id.toString():"",
					
					country_id:1, // 国家id
					province_id:this.items_province.id, // 省份id
					city_id:this.items_city.id, // 城市id
					district_id:this.items_county.id, // 地区id
					
					address:this.minute,
					note:this.remarks
				}).then(res=>{
					if(res.data){
						console.log(res)
						this.$u.toast("审核成功")
						getApp().globalData.seach_show=true
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1500)
					}else{
						this.$u.toast(res.status.error_desc)
					}
				})	
			},
			// 不保存
			save(){
				uni.navigateBack({
					delta:1
				})
			},
			// 省
			province(items){
				this.items_province=items
				this.address_show=!this.address_show
				this.province_name=items.name
				
				this.province_show=true
				this.please=true
				console.log(items)
				this.$H.post("v2/store/shop/region",{
					type:2,
					parent_id:items.parent_id,
					}).then(res=>{
						let arr=res.data.regions
						this.provinceList=arr.filter((item,index)=>{
							if(items.id==item.parent_id){
								return item
							}
						})
				})
					
			},
			//  市
			city(items){
				this.items_city=items
				this.city_show=true
				this.province_show=!this.province_show
				this.city_name=items.name
				
				console.log(items)
				this.please=true
				if(this.city_name==this.province_name){
					this.province_name=""
				}else{
					this.$H.post("v2/store/shop/region",{
						type:3,
						parent_id:items.parent_id,
						}).then(res=>{
							let arr=res.data.regions
							this.cityList=arr.filter((item,index)=>{
								if(items.id==item.parent_id){
									return item
								}
						})
					})
				}
			},
			// 县区
			county(items){
				console.log(items)
				this.items_county=items
				this.county_show=true
				this.county_name=items.name
				this.city_show=false
				
				this.please=true
				this.street_show=true
				this.$H.post("v2/store/shop/region",{
					type:4,
					parent_id:items.parent_id,
					}).then(res=>{
						let arr=res.data.regions
						console.log(res)
						this.countyList=arr.filter((item,index)=>{
							if(items.id==item.parent_id){
								return item
							}
						})
				})
				this.address_name=(this.province_name+this.city_name+this.county_name)
			},
			// 街道
			street(items){
				this.items_street=items
				this.street_name=items.name
				
				this.street_id=items.id
				this.please=false
				console.log(items)
				this.bottomShow=false
				this.address_name=(this.province_name+this.city_name+this.county_name+this.street_name)
			},
			// 省 
			province_tab(items){
				this.county_name=""
				this.street_name=""
				this.city_name=""
				
				this.address_show=true
				this.province_show=false
				this.city_show=false
				this.county_show=false
				this.please=true
			},
			// 市
			city_tab(items){
				this.county_name=""
				this.street_name=""
				
				this.street_id=""
				this.county_show=false
				this.city_show=false
				this.province_show=true
				this.please=true
				this.$H.post("v2/store/shop/region",{
					type:2,
					parent_id:items.parent_id,
					}).then(res=>{
						let arr=res.data.regions
						this.provinceList=arr.filter((item,index)=>{
							if(items.id==item.parent_id){
								return item
							}
						})
				})
			},
			// 县区
			county_tab(items){
				this.street_name=""
				
				this.street_id=""
				this.county_show=false
				this.city_show=true
				this.please=true
				
				this.$H.post("v2/store/shop/region",{
					type:3,
					parent_id:items.parent_id,
					}).then(res=>{
						let arr=res.data.regions
						this.cityList=arr.filter((item,index)=>{
							if(items.id==item.parent_id){
								return item
							}
						})
				})
			},
		},
		onShow() {
			var globalData = getApp().globalData.closeLists; //获取全局变量
			getApp().globalData.closeLists= ''; //修改全局变量
			// 商品分类
			
		},
		onUnload() {
			if(getApp().globalData.tally_item){
				getApp().globalData.tally_item=""
			}
			uni.removeStorageSync("terrace_item")
		},
		onLoad(e) {
			console.log(e)
			this.user_id=this.items.user_id
			this.mobile=this.items.mobile_phone
			this.user_name=this.items.name
			this.company=this.items.company_name
			this.minute=this.items.address
			
			this.tally=this.items.tag_list.map(v=>{
				return {
					...v,
					show:false,
					checked:true
				}
			})
			
			this.$H.post("v2/store/user/rank",{
			}).then(res=>{
				this.user_rank=res
			})
			
			// 地址
			this.$H.post("v2/store/shop/region",{
				device:"",
				client:uni.getStorageSync("client"),
				code:5002,udid:"",
				type:1,parent_id:1,
			}).then(res=>{
				this.address_show=true
				this.please=true
				this.addressList=res.data.regions
				this.u_loadmore=false 
			})
		}
	}
</script>

<style>
	.sub /deep/ .dele{
		background: linear-gradient(to right,#ff9900,#ff9900);
		border-radius: 50upx;
		width: 45%;
		color: #FFFFFF;
		font-size: 30upx;
	}
	.sub /deep/ .dele::after{
		border: none;
		color: #000000;
	}
	.sub /deep/ .rele{
		width: 45%;
		border-radius: 50upx;
		font-size: 30upx;
		background: linear-gradient(to right,#F31E3E,#FB4F37);
	}
	
	.address{
		border-bottom: 1px solid #eaeaea;
	}
	.content_address{
		height: 100%;
	}
	.eradders{
		height: 185upx;
	}
	.active_tab{
		color: #ff3333;
		border-bottom: 3px solid #ff3333;
	}
</style>
